﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LuWeibo.ViewModels
{
    public class ViewModelLocator
    {
        private static LuHomePageViewModel _main;
        private static SquareInfoViewModel _square;
        private static UserInfoViewModel _userVM;
        private static StatusViewModel _statusVM;
        private static StatusDetailViewModel _statusDetailVM;
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ////if (ViewModelBase.IsInDesignModeStatic)
            ////{
            ////    // Create design time view models
            ////}
            ////else
            ////{
            ////    // Create run time view models
            ////}

            CreateMain();
            CreateSquare();
            CreateUserVM();
            CreateStatusVM();
            CreateStatusDetailVM();
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        public static LuHomePageViewModel MainStatic
        {
            get
            {
                if (_main == null)
                {
                    CreateMain();
                }

                return _main;
            }
        }

        public static SquareInfoViewModel SquareStatic
        {
            get
            {
                if (_square == null)
                {
                    CreateSquare();
                }
                return _square;
            }
        }

        public static UserInfoViewModel UserVMStatic
        {
            get
            {
                if (_userVM == null)
                {
                    CreateUserVM();
                }
                return _userVM;
            }
        }

        public static StatusViewModel StausVMStatic
        {
            get
            {
                if (_statusVM == null)
                {
                    CreateStatusVM();
                }
                return _statusVM;
            }
        }

        public static StatusDetailViewModel StatusDetailVMStatic
        {
            get
            {
                if (_statusDetailVM == null)
                {
                    CreateStatusDetailVM();
                }
                return _statusDetailVM;
            }
        }
        /// <summary>
        /// Gets the Main property.
        /// </summary>
        public LuHomePageViewModel Main
        {
            get
            {
                return MainStatic;
            }
        }

        public SquareInfoViewModel Square
        {
            get
            {
                return SquareStatic;
            }
        }

        public UserInfoViewModel UserVM
        {
            get
            {
                return UserVMStatic;
            }
        }

        public StatusViewModel StatusVM
        {
            get
            {
                return StausVMStatic;
            }
        }

        public StatusDetailViewModel StatusDetailVM
        {
            get
            {
                return StatusDetailVMStatic;
            }
        }
        /// <summary>
        /// Provides a deterministic way to create the Main property.
        /// </summary>
        public static void CreateMain()
        {
            if (_main == null)
            {
                _main = new LuHomePageViewModel();
            }
        }

        private static void CreateSquare()
        {
            if (_square == null)
            {
                _square = new SquareInfoViewModel();
            }
        }

        private static void CreateUserVM()
        {
            if (_userVM == null)
            {
                _userVM = new UserInfoViewModel();
            }
        }

        private static void CreateStatusVM()
        {
            if (_statusVM == null)
            {
                _statusVM = new StatusViewModel();
            }
        }

        private static void CreateStatusDetailVM()
        {
            if (_statusDetailVM == null)
            {
                _statusDetailVM = new StatusDetailViewModel();
            }
        }
        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearMain();
            ClearSquare();
            ClearUserVM();
            ClearStatusVM();
            ClearStatusDetailVM();
        }

        /// <summary>
        /// Provides a deterministic way to delete the Main property.
        /// </summary>
        public static void ClearMain()
        {
            _main = null;
        }

        public static void ClearSquare()
        {
            _square = null;
        }

        public static void ClearUserVM()
        {
            _userVM = null;
        }

        public static void ClearStatusVM()
        {
            _statusVM = null;
        }

        public static void ClearStatusDetailVM()
        {
            _statusDetailVM = null;
        }
    }
}
